<!--  -->
<script setup>
import { ref, reactive, toRefs,defineProps, onBeforeMount, onMounted, watchEffect, computed } from 'vue' // eslint-disable-line
import { useStore } from 'vuex'
import { useRoute, useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { useI18n } from 'vue-i18n'

/**
* 仓库
*/
const store = useStore() // eslint-disable-line
const language = computed(() => store.getters.language)
/**
* 路由对象
*/
const route = useRoute() // eslint-disable-line
/**
* 路由实例
*/
const router = useRouter() // eslint-disable-line
// 1-开始创建组件-setup
/**
* Props
*/
defineProps({
  effect: {
    type: String,
    default: 'dark',
    validator: function (value) {
      // 这个值必须匹配下列字符串中的一个
      return ['dark', 'light'].indexOf(value) !== -1
    }
  }
}) // eslint-disable-line
/**
* 数据部分
*/
const i18n = useI18n()
const handleSetLanguage = lang => {
  i18n.locale.value = lang
  store.commit('app/setLanguage', lang)
  ElMessage.success(i18n.t('msg.toast.switchLangSuccess'))
}
const data = reactive({}) // eslint-disable-line
// 2.组件挂载页面之前执行----onBeforeMount
onBeforeMount(() => {})
// 3.-组件挂载到页面之后执行-------onMounted
onMounted(() => {})
watchEffect(() => {})
// 使用toRefs解构
// let { } = { ...toRefs(data) } // eslint-disable-line

</script>
<template>
  <el-dropdown
    trigger="click"
    class="international"
    @command="handleSetLanguage"
  >
    <div>
      <el-tooltip :content="$t('msg.navBar.lang')" :effect="effect">
        <svg-icon icon="language" />
      </el-tooltip>
    </div>
    <template #dropdown>
      <el-dropdown-menu>
        <el-dropdown-item :disabled="language === 'zh'" command="zh">
          中文
        </el-dropdown-item>
        <el-dropdown-item :disabled="language === 'en'" command="en">
          English
        </el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
</template>

<style scoped lang='scss'>
</style>
